<?php
include "DBconn.php";
class InvoiceHeader
{

public function addNewInvoice($VObject)
{ 
	$invoice_code = $this->generateInvoiceCode();
	$query="insert into invoice_header(invoice_code,customer_serialnumber_fk,invoice_term,total_qty,total_amount,discount_type,invoice_discount,invoice_gst,currency_serialnumber_fk,current_rate,invoice_date,invoice_remarks,cre_userid_fk,cre_datetime,activestatus) values ('$invoice_code','$VObject->customer_serialnumber_fk','$VObject->invoice_term','$VObject->total_qty','$VObject->total_amount','$VObject->discount_type','$VObject->invoice_discount','$VObject->invoice_gst','$VObject->currency_serialnumber_fk','$VObject->current_rate','$VObject->invoice_date','$VObject->invoice_remarks','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
    $s=mysql_query($query)or die(mysql_error());
    if ($s)
       {
            $last_id=mysql_insert_id();
			
            foreach ($VObject->pro_serialnumber_fk as $r=>$value)
            {
				$do_detserialnumber_fk=mysql_real_escape_string($VObject->do_detserialnumber_fk[$r]);
				$pro_detserialnumber=mysql_real_escape_string($VObject->pro_detserialnumber[$r]);
				$base_currency_detserialnumber_fk=mysql_real_escape_string($VObject->base_currency_detserialnumber_fk[$r]);
				$pro_qty=mysql_real_escape_string($VObject->pro_qty[$r]);
				$price_per_unit=mysql_real_escape_string($VObject->price_per_unit[$r]);
				$pro_discount=mysql_real_escape_string($VObject->pro_discount[$r]);
				$pro_total_price=mysql_real_escape_string($VObject->pro_total_price[$r]);

				$query2="insert into invoice_pro_details(invoice_serialnumber_fk,do_detserialnumber_fk,pro_serialnumber_fk,pro_detserialnumber,base_currency_detserialnumber_fk,pro_qty,price_per_unit,pro_discount,pro_total_price,cre_userid_fk,cre_datetime,activestatus) values('$last_id','$do_detserialnumber_fk','$value','$pro_detserialnumber','$base_currency_detserialnumber_fk','$pro_qty','$price_per_unit','$pro_discount','$pro_total_price','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
				$s2 = mysql_query($query2) or die(mysql_error());
				
				if($s2)
				{
			       $s3 = mysql_query("update delivery_order_pro_details set is_invoiced=1 where detserialnumber='$do_detserialnumber_fk' and activestatus=1") or die(mysql_error());
				}
			}
        }
} 

public function editInvoice($VObject)
{
	$query="update invoice_header set customer_serialnumber_fk='$VObject->customer_serialnumber_fk',invoice_term='$VObject->invoice_term',total_qty='$VObject->total_qty',total_amount='$VObject->total_amount',discount_type='$VObject->discount_type',invoice_discount='$VObject->invoice_discount',invoice_gst='$VObject->invoice_gst',currency_serialnumber_fk='$VObject->currency_serialnumber_fk',current_rate='$VObject->current_rate',invoice_date='$VObject->invoice_date',invoice_remarks='$VObject->invoice_remarks' where serialnumber='$VObject->serialnumber'";
    $s=mysql_query($query)or die(mysql_error());

    if ($s)
    {
		$result = mysql_query("Select * from invoice_pro_details where invoice_serialnumber_fk='$VObject->serialnumber' and activestatus=1") or die(mysql_error());
		while($row = mysql_fetch_object($result)){
		
			mysql_query("Update invoice_pro_details set activestatus=0 where detserialnumber='$row->detserialnumber'") or die(mysql_error());
			
			$result1 = mysql_query("Select * from invoice_pro_details where activestatus=1 and do_detserialnumber_fk='$row->do_detserialnumber_fk'") or die(mysql_error());
			if(mysql_num_rows($result1)==0){
				mysql_query("Update delivery_order_pro_details set is_invoiced=0 where detserialnumber='$row->do_detserialnumber_fk'") or die(mysql_error());
			}
		}

        foreach ($VObject->pro_serialnumber_fk as $r=>$value)
        {
			$do_detserialnumber_fk=mysql_real_escape_string($VObject->do_detserialnumber_fk[$r]);
			$pro_detserialnumber=mysql_real_escape_string($VObject->pro_detserialnumber[$r]);
			$base_currency_detserialnumber_fk=mysql_real_escape_string($VObject->base_currency_detserialnumber_fk[$r]);
			$pro_qty=mysql_real_escape_string($VObject->pro_qty[$r]);
			$price_per_unit=mysql_real_escape_string($VObject->price_per_unit[$r]);
			$pro_discount=mysql_real_escape_string($VObject->pro_discount[$r]);
			$pro_total_price=mysql_real_escape_string($VObject->pro_total_price[$r]);

			$query2="insert into invoice_pro_details(invoice_serialnumber_fk,do_detserialnumber_fk,pro_serialnumber_fk,pro_detserialnumber,base_currency_detserialnumber_fk,pro_qty,price_per_unit,pro_discount,pro_total_price,cre_userid_fk,cre_datetime,activestatus) values('$VObject->serialnumber','$do_detserialnumber_fk','$value','$pro_detserialnumber','$base_currency_detserialnumber_fk','$pro_qty','$price_per_unit','$pro_discount','$pro_total_price','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
			$s2 = mysql_query($query2) or die(mysql_error());
			
			if($s2)
			{
			    $s3 = mysql_query("update delivery_order_pro_details set is_invoiced=1 where detserialnumber='$do_detserialnumber_fk' and activestatus=1") or die(mysql_error());
			}
		}
    }
}

public function deleteInvoice($VObject)
{
	$query1=("Update invoice_header set invoice_code=concat('Del-',invoice_code),cre_userid_fk='$VObject->cre_userid_fk',cre_datetime='$VObject->cre_datetime',activestatus=0 where serialnumber='$VObject->serialnumber'") or die(mysql_error());
	mysql_query($query1) or die(mysql_error());
	
	$result = mysql_query("Select * from invoice_pro_details where invoice_serialnumber_fk='$VObject->serialnumber' and activestatus=1") or die(mysql_error());
	while($row = mysql_fetch_object($result)){
	
		mysql_query("Update invoice_pro_details set activestatus=0 where detserialnumber='$row->detserialnumber'") or die(mysql_error());
		
		$result1 = mysql_query("Select * from invoice_pro_details where activestatus=1 and do_detserialnumber_fk='$row->do_detserialnumber_fk'") or die(mysql_error());
		if(mysql_num_rows($result1)==0){
			mysql_query("Update delivery_order_pro_details set is_invoiced=0 where detserialnumber='$row->do_detserialnumber_fk'") or die(mysql_error());
		}
	}
}

public function getAllInvoices()
{
    $ret=array();
    $query="Select ih.serialnumber,ih.invoice_code,ih.customer_serialnumber_fk,ih.invoice_term,ih.total_qty,ih.total_amount,ih.discount_type,ih.invoice_discount,ih.invoice_gst,ih.currency_serialnumber_fk,ih.current_rate,ih.invoice_date,ih.invoice_remarks,ih.cre_userid_fk,ih.cre_datetime,ih.activestatus,ch.client_name from invoice_header as ih 
	LEFT JOIN client_header as ch ON ch.serialnumber=ih.customer_serialnumber_fk and ch.activestatus=1 where ih.activestatus=1";
    $s=mysql_query($query) or die(mysql_error());
    while($row=mysql_fetch_object($s))
    {
		$temp=new VoInvoice();
		$temp->serialnumber=(int)$row->serialnumber;
		$temp->invoice_code=$row->invoice_code;
		$temp->customer_serialnumber_fk=(int)$row->customer_serialnumber_fk;
		$temp->invoice_term=(int)$row->invoice_term;
		$temp->total_qty=(int)$row->total_qty;
		$temp->total_amount=(double)$row->total_amount;
		$temp->discount_type=(int)$row->discount_type;
		$temp->invoice_discount=(double)$row->invoice_discount;
		$temp->invoice_gst=(double)$row->invoice_gst;
		$temp->currency_serialnumber_fk=(int)$row->currency_serialnumber_fk;
		$temp->current_rate=(double)$row->current_rate;
		$temp->invoice_date=date("d-m-Y", strtotime($row->invoice_date));
		$temp->invoice_remarks=$row->invoice_remarks;
		$temp->cre_userid_fk=(int)$row->cre_userid_fk;
		$temp->cre_datetime=$row->cre_datetime;
		$temp->activestatus=(boolean)$row->activestatus;
		$temp->client_name=$row->client_name;
	 
		$query2="Select dh.delivery_order_code,id.detserialnumber,id.invoice_serialnumber_fk,id.do_detserialnumber_fk,id.pro_serialnumber_fk,id.pro_detserialnumber,id.base_currency_detserialnumber_fk,id.pro_qty,id.price_per_unit,id.pro_discount,id.pro_total_price,cd.currency_value,ph.pro_name,ph.part_number,ph.stamp_number,ph.pro_description,ph.model_no,id.pro_detserialnumber,prd.currency_serialnumber,prd.markup_type,prd.listprice,prd.discount,prd.markup1,prd.markup2,prd.markup3,prd.markup4,prd.markup5,prd.markup6,prd.default_price from 
		invoice_pro_details as id LEFT JOIN product_details as prd ON prd.pro_detserialnumber=id.pro_detserialnumber LEFT JOIN product_header as ph ON ph.serialnumber=id.pro_serialnumber_fk and ph.activestatus=1 LEFT JOIN currency_detail as cd ON cd.detserialnumber=id.base_currency_detserialnumber_fk and cd.to_currency_fk=prd.currency_serialnumber LEFT JOIN delivery_order_pro_details as dd ON dd.activestatus=1 and dd.detserialnumber=id.do_detserialnumber_fk LEFT JOIN delivery_order_header as dh ON dh.activestatus=1 and 
		dh.serialnumber=dd.delivery_order_fk where id.invoice_serialnumber_fk='$row->serialnumber' and id.activestatus=1";
		$s2=mysql_query($query2) or die(mysql_error());
		while($row2=mysql_fetch_object($s2))
		{
			$temp->detserialnumber[]=(int)$row2->detserialnumber;
			$temp->delivery_order_code[]=$row2->delivery_order_code;
			$temp->invoice_serialnumber_fk[]=(int)$row2->invoice_serialnumber_fk;
			$temp->do_detserialnumber_fk[]=(int)$row2->do_detserialnumber_fk;
			$temp->pro_serialnumber_fk[]=(int)$row2->pro_serialnumber_fk;
			$temp->pro_detserialnumber[]=(int)$row2->pro_detserialnumber;
			$temp->base_currency_detserialnumber_fk[]=(int)$row2->base_currency_detserialnumber_fk;
			$temp->pro_qty[]=(int)$row2->pro_qty;
			$temp->price_per_unit[]=(double)$row2->price_per_unit;
			$temp->pro_discount[]=(double)$row2->pro_discount;
			$temp->pro_total_price[]=(double)$row2->pro_total_price;
			$temp->pro_name[] = $row2->pro_name;
			$temp->part_number[] = $row2->part_number;
			$temp->pro_description[] = $row2->pro_description;
		
			$m1 = (double)$row2->markup1;
				$m2 = (double)$row2->markup2;
				$m3 = (double)$row2->markup3;
				$m4 = (double)$row2->markup4;
				$m5 = (double)$row2->markup5;
				$m6 = (double)$row2->markup6;	
				
				$listprice = (double)$row2->listprice;
				$discount = (double)$row2->discount;
				
				$base_currency_value =(double)$row2->currency_value;
				
				$netprice = round(($listprice - (($discount/100)*$listprice)),2);
			
				$costPrice = $netprice * $base_currency_value;
			    $other_price = $costPrice / $temp->current_rate;
				
				$price1=0;
				$price2=0;
				$price3=0;
				$price4=0;
				$price5=0;
				$price6=0;
				
				$priceQ1=0;
				$priceQ2=0;
				$priceQ3=0;
				$priceQ4=0;
				$priceQ5=0;
				$priceQ6=0;
			
			if($row2->markup_type!='Net Markup')
			 {
				$price1 = round(($costPrice/(1-($m1/100))),4);
				$price2 = round(($costPrice/(1-($m2/100))),4);
				$price3 = round(($costPrice/(1-($m3/100))),4);
				$price4 = round(($costPrice/(1-($m4/100))),4);
				$price5 = round(($costPrice/(1-($m5/100))),4);
				$price6 = round(($costPrice/(1-($m6/100))),4);
			 }else{
				$price1 = round(($costPrice*(1+($m1/100))),4);
				$price2 = round(($costPrice*(1+($m2/100))),4);
				$price3 = round(($costPrice*(1+($m3/100))),4);
				$price4 = round(($costPrice*(1+($m4/100))),4);
				$price5 = round(($costPrice*(1+($m5/100))),4);
				$price6 = round(($costPrice*(1+($m6/100))),4);
			 }
			 
			 $priceQ1 = round(($price1/$temp->current_rate),4);
			 $priceQ2 = round(($price2/$temp->current_rate),4);
			 $priceQ3 = round(($price3/$temp->current_rate),4);
			 $priceQ4 = round(($price4/$temp->current_rate),4);
			 $priceQ5 = round(($price5/$temp->current_rate),4);
			 $priceQ6 = round(($price6/$temp->current_rate),4);
			 
			$priceList = array();

            $priceObj1 = new VOPrice();
            $priceObj1->sgd_price = (double)$price1;
			$priceObj1->other_price = (double)$priceQ1;
            $priceObj1->hilight = 0;
            if ($row2->default_price == 'Price A') {
                $priceObj1->hilight = 1;
            }
            $priceList[] = $priceObj1;

            $priceObj2 = new VOPrice();
            $priceObj2->sgd_price = (double)$price2;
			$priceObj2->other_price = (double)$priceQ2;
            $priceObj2->hilight = 0;
            if ($row2->default_price == 'Price B') {
                $priceObj2->hilight = 1;
            }
            $priceList[] = $priceObj2;

            $priceObj3 = new VOPrice();
            $priceObj3->sgd_price = (double)$price3;
			$priceObj3->other_price = (double)$priceQ3;
            $priceObj3->hilight = 0;
            if ($row2->default_price == 'Price C') {
                $priceObj3->hilight = 1;
            }
            $priceList[] = $priceObj3;

            $priceObj4 = new VOPrice();
            $priceObj4->sgd_price = (double)$price4;
			$priceObj4->other_price = (double)$priceQ4;
            $priceObj4->hilight = 0;
            if ($row2->default_price == 'Price D') {
                $priceObj4->hilight = 1;
            }
            $priceList[] = $priceObj4;

            $priceObj5 = new VOPrice();
            $priceObj5->sgd_price = (double)$price5;
			$priceObj5->other_price = (double)$priceQ5;
            $priceObj5->hilight = 0;
            if ($row2->default_price == 'Price E') {
                $priceObj5->hilight = 1;
            }
            $priceList[] = $priceObj5;

            $priceObj6 = new VOPrice();
            $priceObj6->sgd_price = (double)$price6;
			$priceObj6->other_price = (double)$priceQ6;
            $priceObj6->hilight = 0;
            if ($row2->default_price == 'Price F') {
                $priceObj6->hilight = 1;
            }
            $priceList[] = $priceObj6;

            $temp->price_list[] = $priceList;
            $temp->default_price[] = $row2->default_price;
		}
	  $ret[]=$temp;
	}
	mysql_free_result($s);
    return $ret;
}

public function getInvoiceByCode($serialnumber)
{
	$query="Select ih.serialnumber,ih.invoice_code,ih.customer_serialnumber_fk,ih.invoice_term,ih.total_qty,ih.total_amount,ih.discount_type,ih.invoice_discount,ih.invoice_gst,ih.currency_serialnumber_fk,ih.current_rate,ih.invoice_date,ih.invoice_remarks,ih.cre_userid_fk,ih.cre_datetime,ih.activestatus,ch.client_name from invoice_header as ih 
	LEFT JOIN client_header as ch ON ch.serialnumber=ih.customer_serialnumber_fk and ch.activestatus=1 where ih.activestatus=1 and ih.serialnumber='$serialnumber'";
    $s=mysql_query($query) or die(mysql_error());
    while($row=mysql_fetch_object($s))
    {	
		$temp=new VoInvoice();
		$temp->serialnumber=(int)$row->serialnumber;
		$temp->invoice_code=$row->invoice_code;
		$temp->customer_serialnumber_fk=(int)$row->customer_serialnumber_fk;
		$temp->invoice_term=(int)$row->invoice_term;
		$temp->total_qty=(int)$row->total_qty;
		$temp->total_amount=(double)$row->total_amount;
		$temp->discount_type=(int)$row->discount_type;
		$temp->invoice_discount=(double)$row->invoice_discount;
		$temp->invoice_gst=(double)$row->invoice_gst;
		$temp->currency_serialnumber_fk=(int)$row->currency_serialnumber_fk;
		$temp->current_rate=(double)$row->current_rate;
		$temp->invoice_date=date("d-m-Y", strtotime($row->invoice_date));
		$temp->invoice_remarks=$row->invoice_remarks;
		$temp->cre_userid_fk=(int)$row->cre_userid_fk;
		$temp->cre_datetime=$row->cre_datetime;
		$temp->activestatus=(boolean)$row->activestatus;
		$temp->client_name=$row->client_name;
	 
		$query2="Select id.detserialnumber,id.invoice_serialnumber_fk,id.do_detserialnumber_fk,id.pro_serialnumber_fk,id.pro_detserialnumber,id.base_currency_detserialnumber_fk,id.pro_qty,id.price_per_unit,id.pro_discount,id.pro_total_price,cd.currency_value,ph.pro_name,ph.part_number,ph.stamp_number,ph.pro_description,ph.model_no,id.pro_detserialnumber,prd.currency_serialnumber,prd.markup_type,prd.listprice,prd.discount,prd.markup1,prd.markup2,prd.markup3,prd.markup4,prd.markup5,prd.markup6,prd.default_price from 
		invoice_pro_details as id LEFT JOIN product_details as prd ON prd.pro_detserialnumber=id.pro_detserialnumber LEFT JOIN product_header as ph ON ph.serialnumber=id.pro_serialnumber_fk and ph.activestatus=1 LEFT JOIN currency_detail as cd ON cd.detserialnumber=id.base_currency_detserialnumber_fk and cd.to_currency_fk=prd.currency_serialnumber where id.invoice_serialnumber_fk='$row->serialnumber' and id.activestatus=1";
		$s2=mysql_query($query2) or die(mysql_error());
		while($row2=mysql_fetch_object($s2))
		{
			$temp->detserialnumber[]=(int)$row2->detserialnumber;
			$temp->invoice_serialnumber_fk[]=(int)$row2->invoice_serialnumber_fk;
			$temp->do_detserialnumber_fk[]=(int)$row2->do_detserialnumber_fk;
			$temp->pro_serialnumber_fk[]=(int)$row2->pro_serialnumber_fk;
			$temp->pro_detserialnumber[]=(int)$row2->pro_detserialnumber;
			$temp->base_currency_detserialnumber_fk[]=(int)$row2->base_currency_detserialnumber_fk;
			$temp->pro_qty[]=(int)$row2->pro_qty;
			$temp->price_per_unit[]=(double)$row2->price_per_unit;
			$temp->pro_discount[]=(double)$row2->pro_discount;
			$temp->pro_total_price[]=(double)$row2->pro_total_price;
			$temp->pro_name[] = $row2->pro_name;
			$temp->part_number[] = $row2->part_number;
			$temp->pro_description[] = $row2->pro_description;
		
			$m1 = (double)$row2->markup1;
				$m2 = (double)$row2->markup2;
				$m3 = (double)$row2->markup3;
				$m4 = (double)$row2->markup4;
				$m5 = (double)$row2->markup5;
				$m6 = (double)$row2->markup6;	
				
				$listprice = (double)$row2->listprice;
				$discount = (double)$row2->discount;
				
				$base_currency_value =(double)$row2->currency_value;
				
				$netprice = round(($listprice - (($discount/100)*$listprice)),2);
			
				$costPrice = $netprice * $base_currency_value;
			    $other_price = $costPrice / $temp->current_rate;
				
				$price1=0;
				$price2=0;
				$price3=0;
				$price4=0;
				$price5=0;
				$price6=0;
				
				$priceQ1=0;
				$priceQ2=0;
				$priceQ3=0;
				$priceQ4=0;
				$priceQ5=0;
				$priceQ6=0;
			
			if($row2->markup_type!='Net Markup')
			 {
				$price1 = round(($costPrice/(1-($m1/100))),4);
				$price2 = round(($costPrice/(1-($m2/100))),4);
				$price3 = round(($costPrice/(1-($m3/100))),4);
				$price4 = round(($costPrice/(1-($m4/100))),4);
				$price5 = round(($costPrice/(1-($m5/100))),4);
				$price6 = round(($costPrice/(1-($m6/100))),4);
			 }else{
				$price1 = round(($costPrice*(1+($m1/100))),4);
				$price2 = round(($costPrice*(1+($m2/100))),4);
				$price3 = round(($costPrice*(1+($m3/100))),4);
				$price4 = round(($costPrice*(1+($m4/100))),4);
				$price5 = round(($costPrice*(1+($m5/100))),4);
				$price6 = round(($costPrice*(1+($m6/100))),4);
			 }
			 
			 $priceQ1 = round(($price1/$temp->current_rate),4);
			 $priceQ2 = round(($price2/$temp->current_rate),4);
			 $priceQ3 = round(($price3/$temp->current_rate),4);
			 $priceQ4 = round(($price4/$temp->current_rate),4);
			 $priceQ5 = round(($price5/$temp->current_rate),4);
			 $priceQ6 = round(($price6/$temp->current_rate),4);
			 
			$priceList = array();

            $priceObj1 = new VOPrice();
            $priceObj1->sgd_price = (double)$price1;
			$priceObj1->other_price = (double)$priceQ1;
            $priceObj1->hilight = 0;
            if ($row2->default_price == 'Price A') {
                $priceObj1->hilight = 1;
            }
            $priceList[] = $priceObj1;

            $priceObj2 = new VOPrice();
            $priceObj2->sgd_price = (double)$price2;
			$priceObj2->other_price = (double)$priceQ2;
            $priceObj2->hilight = 0;
            if ($row2->default_price == 'Price B') {
                $priceObj2->hilight = 1;
            }
            $priceList[] = $priceObj2;

            $priceObj3 = new VOPrice();
            $priceObj3->sgd_price = (double)$price3;
			$priceObj3->other_price = (double)$priceQ3;
            $priceObj3->hilight = 0;
            if ($row2->default_price == 'Price C') {
                $priceObj3->hilight = 1;
            }
            $priceList[] = $priceObj3;

            $priceObj4 = new VOPrice();
            $priceObj4->sgd_price = (double)$price4;
			$priceObj4->other_price = (double)$priceQ4;
            $priceObj4->hilight = 0;
            if ($row2->default_price == 'Price D') {
                $priceObj4->hilight = 1;
            }
            $priceList[] = $priceObj4;

            $priceObj5 = new VOPrice();
            $priceObj5->sgd_price = (double)$price5;
			$priceObj5->other_price = (double)$priceQ5;
            $priceObj5->hilight = 0;
            if ($row2->default_price == 'Price E') {
                $priceObj5->hilight = 1;
            }
            $priceList[] = $priceObj5;

            $priceObj6 = new VOPrice();
            $priceObj6->sgd_price = (double)$price6;
			$priceObj6->other_price = (double)$priceQ6;
            $priceObj6->hilight = 0;
            if ($row2->default_price == 'Price F') {
                $priceObj6->hilight = 1;
            }
            $priceList[] = $priceObj6;

            $temp->price_list[] = $priceList;
            $temp->default_price[] = $row2->default_price;
		}
	}
  mysql_free_result($s);
  return $temp;
}

public function generateInvoiceCode()
{
	$query="select invoice_code from invoice_header where activestatus=1 order by serialnumber desc limit 1 ";
    $result = mysql_query($query) or die(mysql_error());
    if(mysql_num_rows($result)){
    $row = mysql_fetch_array($result);
	$str=explode("IN",$row[0]);
    $num=intval($str[1]);
    $res="IN".++$num;
	}else{
	$res='IN1001';
	}
    return $res;
}

public function getInvoiceForCRDB($customerFk)
{
	$ret=array();
    $query="select * from invoice_pro_details as id LEFT JOIN invoice_header as ih ON ih.activestatus=1 and ih.serialnumber=id.invoice_serialnumber_fk 
	LEFT JOIN product_header as ph ON ph.activestatus=1 and ph.serialnumber=id.pro_serialnumber_fk where id.activestatus=1 and id.invoice_serialnumber_fk 
	IN(Select ih.serialnumber from invoice_header as ih where ih.customer_serialnumber_fk='$customerFk' and ih.activestatus=1)";
    $s=mysql_query($query)or die(mysql_error());
	while($row=mysql_fetch_object($s))
    {
		$temp = new VoInvoiceHeaderList();
        $temp->serialnumber = (int) $row->serialnumber;
        $temp->invoice_code = $row->invoice_code;
		$temp->detserialnumber = (int) $row->detserialnumber;
		$temp->pro_serialnumber_fk = (int) $row->pro_serialnumber_fk;
		$temp->pro_name =  $row->pro_name;
		$temp->part_number =  $row->part_number;
		$temp->pro_description =  $row->pro_description;
        $temp->isSelected = false;
		$ret[] = $temp;
	}
  return $ret;
} 

}

class VoInvoiceHeaderList
{
	var $serialnumber;
    var $invoice_code;
    var $detserialnumber;
    var $pro_serialnumber_fk;
	var $pro_name;
	var $part_number;
	var $pro_description;
    var $isSelected;
}

class VoInvoice
{
	var $serialnumber;
	var $invoice_code;
	var $customer_serialnumber_fk;
	var $invoice_term;
	var $total_qty;
	var $total_amount;
	var $discount_type;
	var $invoice_discount;
	var $invoice_gst;
	var $currency_serialnumber_fk;
	var $current_rate;
	var $invoice_date;
	var $invoice_remarks;
	var $client_name;
	var $detserialnumber;
	var $invoice_serialnumber_fk;
	var $do_detserialnumber_fk;
	var $delivery_order_code;
	var $pro_serialnumber_fk;
	var $pro_name;
	var $part_number;
	var $pro_description;
	var $pro_detserialnumber;
	var $base_currency_detserialnumber_fk;
	var $pro_qty;
	var $price_per_unit;
	var $pro_discount;
	var $pro_total_price;
	var $price_list;
	var $cre_userid_fk;
	var $cre_datetime;
	var $activestatus;
}

class VOPrice {
    var $sgd_price;
	var $other_price;
    var $hilight;
}

?>